<template>
  <div>
    <div class="condition">
      <span>
        年份：
        <el-date-picker
          v-model="year"
          type="year"
          value-format="yyyy"
          :clearable="false"
          placeholder="选择年"
          @change="changeYear"
        ></el-date-picker>
      </span>
      <span>姓名：{{yearInfo.userName}}，年份:{{yearInfo.year}}</span>
    </div>

    <div class="manHours">合计工时数：{{sumWorkingHours}}</div>
    <base-table
      ref="baseTable"
      :tableSetting="tableSetting"
      @getdata="getdata"
      @handleCommon="handleCommon"
    ></base-table>
    <!-- 查看工时信息 -->
    <el-dialog title="查看工时信息" :visible.sync="dialogStation" width="1300px" center>
      <el-table
        border
        tooltip-effect="dark"
        :header-cell-style="{background:'#F9F9F9'}"
        :data="tableData"
        v-loading="tableLoading"
        style="width: 100%;"
      >
        <el-table-column prop="id" align="center" label="ID"></el-table-column>
        <el-table-column prop="taskDate" align="center" label="日期"></el-table-column>
        <el-table-column prop="projectName" align="center" label="项目名"></el-table-column>
        <el-table-column prop="time" align="center" label="工时数（天）"></el-table-column>
        <el-table-column prop="content" align="left" width="400" label="工作内容"></el-table-column>
        <el-table-column prop="achievement" align="center" label="业绩属性">
          <template slot-scope="scope">
            <span v-for="(i,j) in scope.row.achievement" :key="j" v-show="i.value">
              {{i.name}}:
              <span>{{i.value}}</span>个
              <br />
            </span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="createTime" align="center" label="提交时间">
        </el-table-column>-->
        <el-table-column value-format="yyyy-MM-dd" prop="createTime" align="center" label="提交时间">
          <template slot-scope="scope">{{scope.row.createTime | dateFormat}}</template>
        </el-table-column>
        <el-table-column prop="isConfirm" align="center" label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.isConfirm==1">已确认</span>
            <span v-else>未确认</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import baseTable from "@/components/table/baseTable";
import { userAnnWorkHours, userProjectDailyList } from "@/service/Api.js"; //接口
export default {
  components: { baseTable },
  props: ["userId"],
  name: "weekly",
  data() {
    return {
      tableSetting: {
        defaulteParams: {
          year: "",
          id: this.userId,
        },
        init: 100,
        tableApiFn: userAnnWorkHours,
        options: [
          { prop: "number", label: "排名" },
          { prop: "projectName", label: "项目" },
          { prop: "sumTime", label: "年度总工时" },
        ],
        btns: [
          {
            text: "查看详情",
            size: "mini",
            handleName: "lookDatil",
            type: "success",
          },
        ],
      },
      year: "",
      sumWorkingHours: "",
      yearInfo: {
        userName: "",
        year: "",
      },
      dialogStation: false,
      tableLoading: false,
      tableData: [],
    };
  },
  created() {
    let date = new Date();
    console.log(date.getFullYear());
    this.year = date.getFullYear() + "";
    this.tableSetting.defaulteParams.year = date.getFullYear();
  },
  methods: {
    handleCommon(name, row, idx) {
      if (this[name]) {
        this[name](row, idx);
      }
    },
    getdata(val) {
      this.yearInfo = val;
      this.sumWorkingHours = val.sumWorkingHours.toFixed(2);
    },
    changeYear() {
      this.tableSetting.defaulteParams.year = this.year;
      this.$refs.baseTable.initData();
    },
    //查看
    lookDatil(row) {
      this.dialogStation = true;
      console.log(row);
      let data = {
        uid: this.userId,
        pid: row.pid,
      };
      userProjectDailyList(data).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data;
          for (var i = 0; i < this.tableData.length; i++) {
            this.tableData[i].achievement = JSON.parse(
              this.tableData[i].achievement
            );
          }
          console.log(this.tableData);
        }
      });
    },
  },
};
</script>

<style scoped>
.condition {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.manHours {
  text-align: center;
  border: 1px solid #ebeef5;
  border-bottom: 0;
  padding: 10px 0;
  color: #707070;
  font-weight: bold;
  background: #f9f9f9;
  margin-top: 10px;
}
</style>
